/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.model.disc.shape;

import br.ufmg.dees.insane.util.IMatrix;
import br.ufmg.dees.insane.util.IVector;


/**
*A class representing a shape function for the triangular element T10.
*
*@author Lucas, Marcelo & Pitangueira, Roque
*@version 1.0
*@since June 2004
*/

public class T10 extends Shape2D 
{
	private static final long serialVersionUID = 1L;

	/** Constructs a shape function for triangular element T10 and sets its type to "T10".*/
	public T10() 
	{
		type = "T10";
	}
	
//********************************************************************************
	
	/** Returns the IVector containing the values of shape function evalueted in provided points.
	*@param g The vector containing the coordinates which the shape function will be evalueted.
	*@return The IVector containing the values of shape function evalueted in provided points.
	*/
	public IVector getShapeFunction(double[] g) 
	{
		double a = g[0];
		double b = g[1];
		
		IVector n = new IVector(10);
		
		double n0 = ((0.5)*((1-a-b)*(-1+3*(1-a-b))*(-2+3*(1-a-b))));
		double n1 = ((0.5)*((9*(1-a-b)*a)*(-1+3*(1-a-b))));
		double n2 = ((0.5)*((9*(1-a-b)*a)*(-1+3*a)));
		double n3 = ((0.5)*((a)*(-1+3*a)*(-2+3*a)));
		double n4 = ((0.5)*((9*a*b)*(-1+3*a)));
		double n5 = ((0.5)*((9*a*b)*(-1+3*b)));
		double n6 = ((0.5)*((b)*(-1+3*b)*(-2+3*b)));
		double n7 = ((0.5)*((9*(1-a-b)*b)*(-1+3*b)));
		double n8 = ((0.5)*((9*(1-a-b)*b)*(-1+3*(1-a-b))));
		double n9 = ((0.5)*(54*a*b*(1-a-b)));
		
		n.setElement(0,n0);
		n.setElement(1,n1);
		n.setElement(2,n2);
		n.setElement(3,n3);
		n.setElement(4,n4);
		n.setElement(5,n5);
		n.setElement(6,n6);
		n.setElement(7,n7);
		n.setElement(8,n8);
		n.setElement(9,n9);
		
		return (n);
	}
	
//********************************************************************************
	
	/** Returns the IMatrix containing the values of shape function derived in xi and eta evalueted in provided points.
	*@param g The vector containing the coordinates which the shape function will be evalueted.
	*@return The IMatrix containing the values of shape function derived in xi and eta evalueted in provided points.
	*/
	public IMatrix getDerivedShapeFunction(double[] g) 
	{
		double a = g[0];
		double b = g[1];
		
		IMatrix dl = new IMatrix(2,10);
		
	//derivadas em relacao a xi_1 (a = xi_1 e b = xi_2)
		double dl0 = ((0.5)*(-2+18*(1-a-b)-27*(1-a-b)*(1-a-b)));
		double dl1 = ((0.5)*((9*(1-a-b))*(-1+3*(1-a-b)-6*a)+(9*a)));
		double dl2 = ((0.5)*((9*a)*(1+6*(1-a-b)-3*a)-(9*(1-a-b))));
		double dl3 = ((0.5)*(2-18*a+27*(a)*(a)));
		double dl4 = ((0.5)*((9*b)*(-1+6*a)));
		double dl5 = ((0.5)*((9*b)*(-1+3*b)));
		double dl6 = (0);
		double dl7 = ((0.5)*((-9*b)*(-1+3*b)));
		double dl8 = ((0.5)*((-9*b)*(-1+6*(1-a-b))));
		double dl9 = ((0.5)*((54*b)*((1-a-b)-a)));
	//derivadas em relacao a xi_2 (a = xi_1 e b = xi_2)
		double dl10 = ((0.5)*(-2+18*(1-a-b)-27*(1-a-b)*(1-a-b)));
		double dl11 = ((0.5)*((-9*a)*(-1+6*(1-a-b))));
		double dl12 = ((0.5)*((-9*a)*(-1+3*a)));
		double dl13 = (0);
		double dl14 = ((0.5)*((9*a)*(-1+3*a)));
		double dl15 = ((0.5)*((9*a)*(-1+6*b)));
		double dl16 = ((0.5)*(2-18*b+27*(b)*(b)));
		double dl17 = ((0.5)*((9*b)*(1+6*(1-a-b)-3*b)-(9*(1-a-b))));
		double dl18 = ((0.5)*((9*(1-a-b))*(-1+3*(1-a-b)-6*b)+(9*b)));
		double dl19 = ((0.5)*((54*a)*((1-a-b)-b)));
		
	//derivadas em relacao a xi_1 na linha 0 da IMatrix
		dl.setElement(0,0,dl0);
		dl.setElement(0,1,dl1);
		dl.setElement(0,2,dl2);
		dl.setElement(0,3,dl3);
		dl.setElement(0,4,dl4);
		dl.setElement(0,5,dl5);
		dl.setElement(0,6,dl6);
		dl.setElement(0,7,dl7);
		dl.setElement(0,8,dl8);
		dl.setElement(0,9,dl9);
	//derivadas em relacao a xi_2 na linha 1 da IMatrix
		dl.setElement(1,0,dl10);
		dl.setElement(1,1,dl11);
		dl.setElement(1,2,dl12);
		dl.setElement(1,3,dl13);
		dl.setElement(1,4,dl14);
		dl.setElement(1,5,dl15);
		dl.setElement(1,6,dl16);
		dl.setElement(1,7,dl17);
		dl.setElement(1,8,dl18);
		dl.setElement(1,9,dl19);
		
		return (dl);
	}
	
//********************************************************************************
	
	/** Return the IMatrix containing nodal coordinates of this shape in natural system.
	*@return natCoords The IMatrix with nodal coordinates of this shape in natural system.
	*/
	public IMatrix getNaturalNodalCoords()
	{
		IMatrix natCoords = new IMatrix(2,10);
		
	//coordenadas naturais de xi_1
		natCoords.setElement(0,0,1);
		natCoords.setElement(0,1,(0.666666666666667));
		natCoords.setElement(0,2,(0.333333333333333));
		natCoords.setElement(0,3,0);
		natCoords.setElement(0,4,0);
		natCoords.setElement(0,5,0);
		natCoords.setElement(0,6,0);
		natCoords.setElement(0,7,(0.333333333333333));
		natCoords.setElement(0,8,(0.666666666666667));
		natCoords.setElement(0,9,(0.333333333333333));
	
	//coordenadas naturais de xi_2
		natCoords.setElement(1,0,0);
		natCoords.setElement(1,1,(0.333333333333333));
		natCoords.setElement(1,2,(0.666666666666667));
		natCoords.setElement(1,3,1);
		natCoords.setElement(1,4,(0.666666666666667));
		natCoords.setElement(1,5,(0.333333333333333));
		natCoords.setElement(1,6,0);
		natCoords.setElement(1,7,0);
		natCoords.setElement(1,8,0);
		natCoords.setElement(1,9,(0.333333333333333));
		
			return natCoords;
	}
	
//********************************************************************************

}

